home *** CD-ROM | disk | FTP | other *** search
- /* DisplayAudit.h */
- /*
- * DisplayAudit.c
- * Copyright © 1992-93, Apple Computer Inc. All Rights Reserved.
- * Programmed by Martin Minow,
- * Internet: minow@apple.com
- * AppleLink: MINOW
- * Version of January 22, 1993
- *
- * Edit History
- * 93.01.09 MM First public release
- * 93.01.22 MM Broke out from DisplayAudit.c
- * 93.07.09 MM Replaced simple text window by Log Manager and many other
- * major revisions.
- */
- /*
- * Resource definitions
- */
- #define ALRT_NonFatal 9000
- #define ALRT_Fatal 9001
- #define MBAR_MenuBar 1
- #define MENU_Apple 1
- #define MENU_File 256
- #define MENU_Edit 257
- #define MENU_Font 258
- #define MENU_FontSize 259
- #define CNTL_FontPopup 256
- #define CNTL_SizePopup 257
- #define WIND_Document 256
- #define DLOG_SFPutFile 4000
- #define STRN_Messages 128 /* Error messages */
- #define STRN_Strings 129 /* Random text strings */
- #define STR_FinderString 128 /* Finder info string for param file */
- /*
- * Preference resource file information.
- * kApplicationCreator is the registered Application Creator ID.
- * kDefaultAuditIdent is the registered Application Creator ID for the sample
- * CSAM - I used this because it's convenient (and that's
- * what I'm debugging).
- */
- #define kApplicationCreator 'MAM1' /* Registered application creator */
- #define kDefaultAuditIdent 'Pdsm' /* kDSAMCreatorID */
- #define kPreferenceFileType 'pref' /* Preference fileType */
- #define PARM_ResourceID 1024 /* We'll create this resource */
- #define STR_FinderIDString (-16397) /* Resource id of help message */
- #define kNoParamFile (-1) /* Signal no parameter file created */
- #define kDefaultAuditRecords 128 /* How many audit records to make */
- #define kDefaultDisplayLines 512 /* How many lines to keep in memory */
- #define kMinWindowWidth 64 /* Minimum width in pixels */
- #define kMinWindowHeight 64 /* Minimum height in pixels */
- #define kScrollBarWidth 16
- #define kScrollBarOffset (kScrollBarWidth - 1)
- #ifndef REZ
- #ifndef THINK_C
- #include <Errors.h>
- #include <Finder.h>
- #include <Folders.h>
- #include <Script.h>
- #include <Types.h>
- #include <Resources.h>
- #include <QuickDraw.h>
- #include <Fonts.h>
- #include <Events.h>
- #include <Windows.h>
- #include <Menus.h>
- #include <TextEdit.h>
- #include <Dialogs.h>
- #include <Desk.h>
- #include <ToolUtils.h>
- #include <Memory.h>
- #include <Files.h>
- #include <OSUtils.h>
- #include <OSEvents.h>
- #include <DiskInit.h>
- #include <Traps.h>
- #endif
- #include <GestaltEqu.h>
- #include <Packages.h>
- #include <Processes.h>
- #include "Audit.h"
- #include "Failure.h"
- #include "LogManager.h"
-
- #ifndef TRUE
- #define TRUE 1
- #define FALSE 0
- #endif
- #ifndef EXTERN
- #define EXTERN extern /* Not in main program */
- #endif
-
- /*
- * These are the "SleepTime" parameters for WaitNextEvent. The idea is that we
- * sleep for a long time if we're in the background; for a short time if active.
- */
- #define kForegroundTicks 6
- #define kBackgroundTicks 60
-
- enum AppleMenu {
- kAppleAbout = 1
- };
-
- enum FileMenu {
- kFileNewWindow = 1,
- kFileCloseWindow,
- kFileUnused1,
- kFileSaveAs,
- kFileCloseFile,
- kFileUnused2,
- kFileQuit
- };
-
- enum EditMenu {
- kEditUndo = 1,
- kEditUnused,
- kEditCut,
- kEditCopy,
- kEditPaste,
- kEditClear
- };
-
- /*
- * Error alert messages. These are in resource (STR# STRN_Messages)
- */
- enum {
- kNoMessage = 0,
- kErrInitialization,
- kErrNoMemory,
- kErrCreateAuditRecord,
- kErrCreateTextWindow,
- kErrSystemVersion,
- kErrFindPreferenceFolder,
- kErrFindPreferenceFile,
- kErrOpenPreferenceFile,
- kErrCreatePreferenceFile,
- kErrWritePreferenceResource,
- kErrReadPreferenceResource,
- kErrCreateOutputFile,
- kErrWriteOutputFile,
- kErrCloseOutputFile,
- kDummyLastMessage
- };
-
- /*
- * Random text messages. These are in resource ('STR#' STRN_Strings)
- */
- enum {
- kAuditParameterFileName = 1,
-
- kDummyLastString
- };
-
- /*
- * This is the content of the Preferences file.
- */
- typedef struct Parameters {
- OSType auditIdent; /* Default Audit ident */
- long enableAudit; /* TRUE to start auditing */
- long auditRecords; /* Number of audit records */
- long logDisplayLines; /* Number of display lines */
- long fontSize; /* Font height in pixels */
- Str255 fontName; /* User's chosen font */
- } Parameters;
-
- /*
- * All document-specific variables are in this structure. This allows us to
- * extend DisplayAudit so one application can watch several Audit Records.
- */
- typedef struct DocumentRecord {
- WindowRecord windowRecord; /* In this window - must be first */
- ListHandle logListHandle; /* Display log */
- OSType auditIdent; /* Watching this audit record */
- AuditPtr auditPtr; /* Really atching this audit record */
- AuditEntry currentAuditEntry; /* Working on this one */
- short scanCount; /* Equals number of Audit Records */
- unsigned long totalMissedCount; /* Total number of missed records */
- unsigned long logIndex; /* Current record being displayed */
- Boolean enableAudit; /* TRUE if auditing enabled */
- ProcessSerialNumber oldPSN; /* Previous DisplayAudit Process */
- short logFileRefNum; /* Writing to this file if non-zero */
- short logFileVRefNum; /* Writing to this volume */
- Str63 logFileName; /* Writing to this named file */
- } DocumentRecord, *DocumentPtr;
- /*
- * All functions have a "documentPtr" parameter.
- */
- #define DOC (*documentPtr)
- #define WINDOW_PTR ((WindowPtr) &DOC.windowRecord)
- #define WINDOW (*WINDOW_PTR)
- #define ENTRY (DOC.currentAuditEntry)
- #define IsOurWindow(theWindow) ( \
- (theWindow) != NULL \
- && ((WindowPeek) (theWindow))->windowKind == userKind \
- )
- /*
- * AuditDocument.c: DisplayAudit Document Management
- */
- void MakeDocumentWindow(void);
- void ProcessAuditDocument(
- register DocumentPtr documentPtr
- );
- void ProcessAuditEntry(
- register DocumentPtr documentPtr
- );
- void DoWindowKeyDown(
- register DocumentPtr documentPtr
- );
- void DoContentClick(
- register DocumentPtr documentPtr
- );
- void UpdateDocumentWindow(
- register DocumentPtr documentPtr
- );
- void ActivateDocumentWindow(
- register DocumentPtr documentPtr,
- Boolean isActivating
- );
- void DisposeDocumentWindow(
- register DocumentPtr documentPtr
- );
- void DecorateWindow(
- register DocumentPtr documentPtr
- );
- void DoDocumentSaveAs(
- register DocumentPtr documentPtr
- );
- void DoDocumentCloseFile(
- register DocumentPtr documentPtr
- );
-
- /*
- * WindowUtilities.c
- */
- Boolean DoGrowWindow(
- register WindowPtr theWindow,
- short minWindowWidth,
- short minWindowHeight
- );
- void DoZoomWindow(
- register WindowPtr theWindow,
- short whichPart
- );
- /*
- * AuditFileDialog.c
- */
- void AuditFileDialog(
- short dialogID,
- ConstStr255Param promptString,
- ConstStr255Param originalName,
- SFReply *reply
- );
-
- /*
- * DisplayAuditFile.c
- */
- /*
- * File functions
- */
- void PromptAndCreateAuditOutputFile(
- ConstStr255Param promptString,
- ConstStr255Param defaultFileName,
- OSType creator,
- short *fileRefNum,
- short *volumeRefNum,
- Str63 fileName
- );
- OSErr CreateOutputFile(
- OSType creator,
- ConstStr255Param fileName,
- short vRefNum,
- short *fileRefNum
- );
- void WriteAuditOutputLine(
- ConstStr255Param theText,
- short fileRefNum
- );
- void CloseAuditOutputFile(
- OSErr status,
- short fileRefNum,
- short volumeRefNum,
- ConstStr255Param fileName
- );
-
- /*
- * DisplayAuditPreferences.c
- */
- void OpenAuditParameterFile(void);
- void ReadAuditParameters(void);
- void WriteAuditParameters(void);
- void ParameterFactorySettings(void);
- OSErr SearchForCreatorType(
- short prefVRefNum,
- long prefDirID,
- Str63 trueFileName
- );
-
- void ErrorAlert(
- OSErr status,
- short messageIndex,
- Boolean fatal
- );
-
- #define height(box) (box.bottom - box.top)
- #define width(box) (box.right - box.left)
- /*
- * Cheap 'n dirty pascal string copy routine.
- */
- #define pstrcpy(dst, src) do { \
- StringPtr _src = (src); \
- BlockMove(_src, dst, _src[0] + 1); \
- } while (0)
- /*
- * Cheap 'n dirty pascal string concat.
- */
- #define pstrcat(dst, src) do { \
- StringPtr _dst = (dst); \
- StringPtr _src = (src); \
- short _len; \
- _len = 255 - _dst[0]; \
- if (_len > _src[0]) _len = _src[0]; \
- BlockMove(&_src[1], &_dst[1] + _dst[0], _len); \
- _dst[0] += _len; \
- } while (0)
- /*
- * Cheap 'n dirty memory clear routine.
- */
- #define CLEAR(record) do { \
- register char *ptr = (char *) &record; \
- register long size; \
- for (size = sizeof record; size > 0; --size) \
- *ptr++ = 0; \
- } while (0)
-
- /*
- * Globals
- */
- EXTERN EventRecord gEventRecord;
- #define EVENT (gEventRecord)
- EXTERN Parameters gParameterRecord;
- #define PARM (gParameterRecord)
- EXTERN short gParameterFileRefNum;
- EXTERN short gOpenWindowCount;
- EXTERN Boolean gInForeground;
- EXTERN Boolean gParameterUpdateNeeded;
- EXTERN Boolean gUpdateMenusNeeded;
- EXTERN short gWindowOffset;
- EXTERN Boolean gHasColorQuickDraw;
- /*
- * We only want to set the old PSN once. Otherwise, there's a risk of garbling
- * the Audit PSN if the user closes windows in a different order.
- */
- EXTERN Boolean gHaveOldPSN; /* gOldPSN set already */
- EXTERN ProcessSerialNumber gMyPSN;
- EXTERN Boolean gQuitNow;
- EXTERN MenuHandle gAppleMenu;
- EXTERN MenuHandle gFileMenu;
- EXTERN MenuHandle gEditMenu;
- EXTERN MenuHandle gFontMenu;
- EXTERN MenuHandle gFontSizeMenu;
-
- #endif /* REZ */
-